package com.myapi.controller;

import com.myapi.controller.constructor.ApiConstructor;
import com.myapi.controller.response.ApiResponse;
import com.myapi.model.Content;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;


@RestController
@RequestMapping(value = "api")
public class ApiController {

    @CrossOrigin
    @GetMapping("/get")
    public ApiResponse getApi() {
        return getCont();
    }

    @CrossOrigin
    @GetMapping(value = "/getData")
    public ApiResponse getData() {
        return getCont();
    }
    @CrossOrigin
    @PostMapping("/post")
    public ApiResponse postApi() {
        return getCont();
    }
    @CrossOrigin
    @PostMapping(value = "/postData")
    public ApiResponse postData() {
        return getCont();
    }

    private ApiResponse getCont() {
        ApiConstructor apiConstructor = new ApiConstructor();
        ArrayList<Content> contentList = apiConstructor.getCont();
        // 设置返回的参数
        ApiResponse response = new ApiResponse();
        response.setContents(contentList);
        return response;
    }
}
